<?php
// 本类由系统自动生成，仅供测试用途
class IndexAction extends BaseAction {
    public function index()
    {

        import('ORG.Util.Page');// 导入分页类
        $count      =  M('Zhaopin')->where('status=1')->count();// 查询满足要求的总记录数
        $Page       = new Page($count,150);// 实例化分页类 传入总记录数和每页显示的记录数
        $show       = $Page->show();// 分页显示输出
        // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
        $temp = M('Zhaopin')->where('status=1 and top!=1 and top!=3')->limit($Page->firstRow.','.$Page->listRows)->order('top DESC,createtime desc')->select();

        foreach ($temp as $v){

            $cate =M('Category')->where("id=".$v['cid'])->find();

            $v['city'] = M('City')->where("id=".$v['cityid'])->getField("pinyin");

            $v['catename'] = $cate['name'];

            $v['catepath'] = $cate['path'];

            $info[]=$v;

        }
        $this->assign('zhaopin',$info);// 赋值数据集
        $this->assign('page',$show);// 赋值分页输出




        //import('ORG.Util.Page');// 导入分页类
        // $Page       = new Page(500,50);// 实例化分页类 传入总记录数和每页显示的记录数
        //  $show       = $Page->show();
        if(S('infom')){
            $infom = S('infom');
        }else{

            $tempm = M('Zhaopin')->where('status=1 and top!=1 and top!=3')->limit(0, 100)->order('top DESC,createtime desc')->select();

            foreach ($tempm as $u) {

                $cate = M('Category')->where("id=" . $u['cid'])->find();

                $u['city'] = M('City')->where("id=" . $u['cityid'])->getField("pinyin");

                $u['catename'] = $cate['name'];

                $u['catepath'] = $cate['path'];

                $infom[] = $u;

            }
            S("infom",$infom,60);
        }

        //广告位

        $homead =M('Ad')->where(array('type'=>'homeads','endtime'=>array('gt',time())))->select();

        $this->assign("homead",$homead);
        //print_r($info);
        /*友情链接*/
        $linklist = M('link')->where(array('cityid'=>array('in','0,371')))->order('id ASC')->select();

        //推广
        $spread = M('Zhaopin')->where("spread_sort <> 0 and spread_sort_time > '".date('Y-m-d H:i:s')."' ")->order('spread_sort +0 asc')->select();
        foreach ($spread as $u) {

            $cate = M('Category')->where("id=" . $u['cid'])->find();

            $u['city'] = M('City')->where("id=" . $u['cityid'])->getField("pinyin");

            $u['catename'] = $cate['name'];

            $u['catepath'] = $cate['path'];

            $spreadArr[] = $u;

        }
        $this->assign('spread', $spreadArr);

        $this->assign('info',$info);
        $this->assign('infom',$infom);
        $this->assign('linklist',$linklist);
        $this->display();
    }

    function city(){

        $this->display();
    }
}